<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.dishdex.menuhub.module.mapper.${entity}Mapper">
    <insert id="insert${entity}" parameterType="com.dishdex.menuhub.module.entity.${entity}"
            useGeneratedKeys="true" keyProperty="id">
        insert into ${entity?uncap_first}
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <#list table.fields as field>
                <#if field.keyFlag>
                <#elseif field.columnName == "is_deleted">
                <#elseif field.columnName == "create_time">
                <#elseif field.columnName == "update_time">
                <#elseif field.propertyType == "String">
                    <if test="${field.propertyName} != null and ${field.propertyName}!=''">${field.columnName},</if>
                <#else>
                    <if test="${field.propertyName} != null">${field.columnName},</if>
                </#if>
            </#list>
            create_time,
            update_time,
            is_deleted
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <#list table.fields as field>
                <#if field.keyFlag>
                <#elseif field.columnName == "is_deleted">
                <#elseif field.columnName == "create_time">
                <#elseif field.columnName == "update_time">
                <#elseif field.propertyType == "String">
                    <if test="${field.propertyName} != null and ${field.propertyName}!=''"><#noparse>#{</#noparse>${field.propertyName}<#noparse>},</#noparse></if>
                <#else>
                    <if test="${field.propertyName} != null"><#noparse>#{</#noparse>${field.propertyName}<#noparse>},</#noparse></if>
                </#if>
            </#list>
            <#noparse>
                #{createTime},
                #{updateTime},
                #{isDeleted}
            </#noparse>
        </trim>
    </insert>

    <update id="update${entity}" parameterType="com.dishdex.menuhub.module.entity.${entity}">
            update ${entity?uncap_first}
            <set>
                <#list table.fields as field>
                    <#if field.keyFlag>
                        <#elseif field.columnName == "is_deleted">
                        <#elseif field.columnName == "create_time">
                        <#elseif field.columnName == "update_time">
                        <#elseif field.propertyType == "String">
                        <if test="${field.propertyName} != null and ${field.propertyName}!=''">${field.columnName}=<#noparse>#{</#noparse>${field.propertyName}<#noparse>},</#noparse></if>

                        <#else>
                            <if test="${field.propertyName} != null">${field.columnName}=<#noparse>#{</#noparse>${field.propertyName}<#noparse>},</#noparse></if>
                    </#if>
                </#list>
                update_time=<#noparse>#{updateTime}</#noparse>
            </set>
            where id = <#noparse>#{id}</#noparse> and is_deleted = 0;
    </update>
</mapper>